package 经典排序;

import java.util.PriorityQueue;

public class NC88寻找第K大的数 {

    public int findKth(int[] a, int n, int K) {
        // write code here
        PriorityQueue<Integer> priorityQueue=new PriorityQueue<>();
        for (int i = 0; i < K; i++) {
            priorityQueue.add(a[i]);
        }
        for (int i = K; i < a.length; i++) {
            if(priorityQueue.peek()<a[i]){
                priorityQueue.remove();
                priorityQueue.add(a[i]);
            }
        }
        return priorityQueue.peek();
    }

}
